package config

// Config 配置结构体
type Config struct {
	Server   ServerConfig   `yaml:"server"`
	Database DatabaseConfig `yaml:"database"`
	Redis    RedisConfig    `yaml:"redis"`
	Elastic  ElasticConfig  `yaml:"elastic"`
	App      AppSettings    `yaml:"app"`
}

type ServerConfig struct {
	Host string `yaml:"host"`
	Port string `yaml:"port"`
}

type DatabaseConfig struct {
	Driver   string `yaml:"driver"`
	Host     string `yaml:"host"`
	Port     string `yaml:"port"`
	Username string `yaml:"username"`
	Password string `yaml:"password"`
	Database string `yaml:"database"`
	Charset  string `yaml:"charset"`
}

type RedisConfig struct {
	Host     string `yaml:"host"`
	Port     string `yaml:"port"`
	Password string `yaml:"password"`
	DB       int    `yaml:"db"`
}

type ElasticConfig struct {
	URL             string `yaml:"url"`
	IndexNamePost   string `yaml:"index_name_post"`
	IndexNameAccess string `yaml:"index_name_access"`
}

type AppSettings struct {
	UserPassExt         string `yaml:"user_pass_ext"`
	RequestLogFile      string `yaml:"request_log_file"`
	ErrorLogFile        string `yaml:"error_log_file"`
	ServiceStartLogFile string `yaml:"service_start_log_file"`
	SessionTime         int    `yaml:"session_time"`
}

// Mysql
var DbCfg = struct {
	DbUser string
	DbPass string
	DbHost string
	DbPort string
	DbName string
}{}

// Http
var HttpCfg = struct {
	Listen string
	Port   string
}{}

// Redis
var RedisConf = struct {
	Network  string
	Address  string
	Password string
	DB       int
}{}

// 运行配置
var RunCFG = struct {
	UserPassExt         string //用户密码扩展加密串
	RequestLogFile      string //请求日志文件
	ErrorLogFile        string //错误日志文件
	ServiceStartLogFile string //服务启动日志
	SessionTime         int    //Session缓存时长
}{}

var EsConf = map[string]string{
	"INDEX_POST_MAPPING": `{
		"posts": {
			"properties": {
				"id": {"type": "integer"},
				"type":{"type": "integer"},
				"title": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_max_word"},
				"content": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_max_word"},
				"create_time":{"type":"date"}
			}
		}
	}`,
}
